﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace PROAD.admin.Consulta
{
    public partial class ConsultaProfissionais : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if(!IsPostBack)
            {
                CarregarDDl();
                CarregarGrid();
            }
        }

        protected void CarregarDDl() 
        {
            var metAuxiliar = new DADOS.auxiliares.metProfissional();

            var list = metAuxiliar.ListarCategoriaProf();
            ddlTipo.DataSource = list;
            ddlTipo.DataBind();
            ddlTipo.Items.Insert(0, new ListItem("Todas Categorias", "0"));
        }

        protected void btnPesquisar_Click(object sender, EventArgs e)
        {
            CarregarGrid();
        }

        protected void CarregarGrid() 
        {
            var metProfissional = new DADOS.usuario.metUsuario();
            var list = metProfissional.ListarProficionais(txtNome.Text,txtCpf.Text,ddlTipo.SelectedValue);
            gridProf.DataSource = list;
            gridProf.DataBind();
        }

        protected void gridUs_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            int id = Convert.ToInt32(e.CommandArgument);

            switch (e.CommandName)
            {
                case "Editar":
                    Response.Redirect("/admin/Forms/FormProfissionais.aspx?cod=" + id);
                    break;
                case "Status":
                    var metUsuario = new DADOS.usuario.metUsuario();
                    metUsuario.TrocarStatus(id);
                    CarregarGrid();
                    break;
            }
        }

        protected void btnLimpar_Click(object sender, EventArgs e)
        {
            Response.Redirect("/admin/Consulta/ConsultaProfissionais.aspx");
        }

    }
}